package com.credit.mola.app.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.credit.mola.lib_baseadapter.SikadwaRecyclerViewAdapter
import com.credit.mola.lib_baseadapter.SikadwaViewHolderHelper
import com.credit.mola.app.R
import com.credit.mola.app.utils.gilde.ImageUtil
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/19 12:02
 * @Annotation：确认绑卡适配器
 */
class ProcessAccountAdapter(recyclerView: RecyclerView?): SikadwaRecyclerViewAdapter<JSONObject>(recyclerView) {

    override fun getItemViewType(position: Int): Int {
        val model = getItem(position)
        if (model.optBoolean("isEdit",false)){
            return R.layout.item_process_account_edit
        }
        return R.layout.item_process_account
    }

    override fun setItemChildListener(helper: SikadwaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.editLayout) //点击编辑
        helper.setItemChildClickListener(R.id.bindedLayout) //点击查看
        helper.setItemChildClickListener(R.id.deleteLayout)//删除
    }

    override fun fillData(helper: SikadwaViewHolderHelper, position: Int, model: JSONObject) {
        helper.setText(R.id.tvIndex,String.format(mContext.getString(R.string.personal_account_index),position+1))

        //是否是编辑
        val isEdit = model.optBoolean("isEdit",true)
        if (!isEdit){
            helper.setText(R.id.textName,model.optString("walletDesc"))
            helper.setText(R.id.textMobile,"+" + model.optString("walletMobile"))

            val imgLogo = helper.getImageView(R.id.imgLogo)
            ImageUtil.instance?.loadImageUrl(mContext,imgLogo,model.optString("walletLogo"),R.mipmap.img_holder)

            //审核中状态，不显示删除账户按钮
            if (model.has("isShowDelete") && !model.optBoolean("isShowDelete")){
                helper.setVisibility(R.id.deleteLayout, View.GONE)
            } else {
                helper.setVisibility(R.id.deleteLayout, View.VISIBLE)
            }
        }
    }
}